﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace KelonProud.Migrations
{
    public partial class init : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "KpAuditLogs",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: true),
                    ServiceName = table.Column<string>(maxLength: 256, nullable: true),
                    MethodName = table.Column<string>(maxLength: 256, nullable: true),
                    Parameters = table.Column<string>(maxLength: 1024, nullable: true),
                    ExecutionTime = table.Column<DateTime>(nullable: false),
                    ExecutionDuration = table.Column<int>(nullable: false),
                    ClientIpAddress = table.Column<string>(maxLength: 64, nullable: true),
                    ClientName = table.Column<string>(maxLength: 128, nullable: true),
                    BrowserInfo = table.Column<string>(maxLength: 512, nullable: true),
                    Exception = table.Column<string>(maxLength: 2000, nullable: true),
                    ImpersonatorUserId = table.Column<long>(nullable: true),
                    ImpersonatorTenantId = table.Column<int>(nullable: true),
                    CustomData = table.Column<string>(maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpAuditLogs", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpAuthority",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(maxLength: 100, nullable: true),
                    Code = table.Column<string>(maxLength: 100, nullable: true),
                    Remak = table.Column<string>(maxLength: 300, nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpAuthority", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpBackgroundJobs",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    JobType = table.Column<string>(maxLength: 512, nullable: false),
                    JobArgs = table.Column<string>(maxLength: 1048576, nullable: false),
                    TryCount = table.Column<short>(nullable: false),
                    NextTryTime = table.Column<DateTime>(nullable: false),
                    LastTryTime = table.Column<DateTime>(nullable: true),
                    IsAbandoned = table.Column<bool>(nullable: false),
                    Priority = table.Column<byte>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpBackgroundJobs", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpEditions",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    Name = table.Column<string>(maxLength: 32, nullable: false),
                    DisplayName = table.Column<string>(maxLength: 64, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpEditions", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpLanguages",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(maxLength: 10, nullable: false),
                    DisplayName = table.Column<string>(maxLength: 64, nullable: false),
                    Icon = table.Column<string>(maxLength: 128, nullable: true),
                    IsDisabled = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpLanguages", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpLanguageTexts",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    LanguageName = table.Column<string>(maxLength: 10, nullable: false),
                    Source = table.Column<string>(maxLength: 128, nullable: false),
                    Key = table.Column<string>(maxLength: 256, nullable: false),
                    Value = table.Column<string>(maxLength: 67108864, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpLanguageTexts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpNotifications",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    NotificationName = table.Column<string>(maxLength: 96, nullable: false),
                    Data = table.Column<string>(maxLength: 1048576, nullable: true),
                    DataTypeName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityTypeName = table.Column<string>(maxLength: 250, nullable: true),
                    EntityTypeAssemblyQualifiedName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityId = table.Column<string>(maxLength: 96, nullable: true),
                    Severity = table.Column<byte>(nullable: false),
                    UserIds = table.Column<string>(maxLength: 131072, nullable: true),
                    ExcludedUserIds = table.Column<string>(maxLength: 131072, nullable: true),
                    TenantIds = table.Column<string>(maxLength: 131072, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpNotifications", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpNotificationSubscriptions",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    NotificationName = table.Column<string>(maxLength: 96, nullable: true),
                    EntityTypeName = table.Column<string>(maxLength: 250, nullable: true),
                    EntityTypeAssemblyQualifiedName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityId = table.Column<string>(maxLength: 96, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpNotificationSubscriptions", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpOrganizationUnits",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    ParentId = table.Column<long>(nullable: true),
                    Code = table.Column<string>(maxLength: 95, nullable: false),
                    DisplayName = table.Column<string>(maxLength: 128, nullable: false),
                    Discriminator = table.Column<string>(nullable: false),
                    NamePath = table.Column<string>(nullable: true),
                    IdPath = table.Column<string>(nullable: true),
                    Icon = table.Column<string>(nullable: true),
                    Level = table.Column<byte>(nullable: true),
                    OrganizationType = table.Column<byte>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpOrganizationUnits", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpOrganizationUnits_KpOrganizationUnits_ParentId",
                        column: x => x.ParentId,
                        principalTable: "KpOrganizationUnits",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpSystemIcon",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(maxLength: 20, nullable: true),
                    CssContent = table.Column<string>(maxLength: 50, nullable: true),
                    Type = table.Column<string>(maxLength: 20, nullable: true),
                    Keywords = table.Column<string>(maxLength: 80, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpSystemIcon", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpTableCategory",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(maxLength: 50, nullable: true),
                    Code = table.Column<string>(maxLength: 10, nullable: true),
                    Level = table.Column<int>(nullable: false),
                    Order = table.Column<int>(nullable: false),
                    ParentId = table.Column<int>(nullable: true),
                    Remark = table.Column<string>(maxLength: 255, nullable: true),
                    IdPath = table.Column<string>(maxLength: 100, nullable: true),
                    NamePath = table.Column<string>(maxLength: 100, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpTableCategory", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpTableCategory_KpTableCategory_ParentId",
                        column: x => x.ParentId,
                        principalTable: "KpTableCategory",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpTableDataBases",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(maxLength: 100, nullable: true),
                    Type = table.Column<byte>(maxLength: 100, nullable: false),
                    ConnectStr = table.Column<string>(maxLength: 100, nullable: true),
                    ConfigJson = table.Column<string>(maxLength: 100, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpTableDataBases", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpTenantNotifications",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    NotificationName = table.Column<string>(maxLength: 96, nullable: false),
                    Data = table.Column<string>(maxLength: 1048576, nullable: true),
                    DataTypeName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityTypeName = table.Column<string>(maxLength: 250, nullable: true),
                    EntityTypeAssemblyQualifiedName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityId = table.Column<string>(maxLength: 96, nullable: true),
                    Severity = table.Column<byte>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpTenantNotifications", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpUserAccounts",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    UserLinkId = table.Column<long>(nullable: true),
                    UserName = table.Column<string>(maxLength: 256, nullable: true),
                    EmailAddress = table.Column<string>(maxLength: 256, nullable: true),
                    LastLoginTime = table.Column<DateTime>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpUserAccounts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpUserLoginAttempts",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TenantId = table.Column<int>(nullable: true),
                    TenancyName = table.Column<string>(maxLength: 64, nullable: true),
                    UserId = table.Column<long>(nullable: true),
                    UserNameOrEmailAddress = table.Column<string>(maxLength: 255, nullable: true),
                    ClientIpAddress = table.Column<string>(maxLength: 64, nullable: true),
                    ClientName = table.Column<string>(maxLength: 128, nullable: true),
                    BrowserInfo = table.Column<string>(maxLength: 512, nullable: true),
                    Result = table.Column<byte>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpUserLoginAttempts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpUserNotifications",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    TenantNotificationId = table.Column<Guid>(nullable: false),
                    State = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpUserNotifications", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpUserOrganizationUnits",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    OrganizationUnitId = table.Column<long>(nullable: false),
                    IsDeleted = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpUserOrganizationUnits", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KpFeatures",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(maxLength: 128, nullable: false),
                    Value = table.Column<string>(maxLength: 2000, nullable: false),
                    Discriminator = table.Column<string>(nullable: false),
                    EditionId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpFeatures", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpFeatures_KpEditions_EditionId",
                        column: x => x.EditionId,
                        principalTable: "KpEditions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpUsers",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    AuthenticationSource = table.Column<string>(maxLength: 64, nullable: true),
                    UserName = table.Column<string>(maxLength: 256, nullable: false),
                    TenantId = table.Column<int>(nullable: true),
                    EmailAddress = table.Column<string>(maxLength: 256, nullable: false),
                    Name = table.Column<string>(maxLength: 64, nullable: false),
                    Surname = table.Column<string>(maxLength: 64, nullable: false),
                    Password = table.Column<string>(maxLength: 128, nullable: false),
                    EmailConfirmationCode = table.Column<string>(maxLength: 328, nullable: true),
                    PasswordResetCode = table.Column<string>(maxLength: 328, nullable: true),
                    LockoutEndDateUtc = table.Column<DateTime>(nullable: true),
                    AccessFailedCount = table.Column<int>(nullable: false),
                    IsLockoutEnabled = table.Column<bool>(nullable: false),
                    PhoneNumber = table.Column<string>(maxLength: 32, nullable: true),
                    IsPhoneNumberConfirmed = table.Column<bool>(nullable: false),
                    SecurityStamp = table.Column<string>(maxLength: 128, nullable: true),
                    IsTwoFactorEnabled = table.Column<bool>(nullable: false),
                    IsEmailConfirmed = table.Column<bool>(nullable: false),
                    IsActive = table.Column<bool>(nullable: false),
                    LastLoginTime = table.Column<DateTime>(nullable: true),
                    NormalizedUserName = table.Column<string>(maxLength: 256, nullable: false),
                    NormalizedEmailAddress = table.Column<string>(maxLength: 256, nullable: false),
                    ConcurrencyStamp = table.Column<string>(maxLength: 128, nullable: true),
                    OrganizationUnitId = table.Column<long>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpUsers", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpUsers_KpUsers_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpUsers_KpUsers_DeleterUserId",
                        column: x => x.DeleterUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpUsers_KpUsers_LastModifierUserId",
                        column: x => x.LastModifierUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpUsers_KpOrganizationUnits_OrganizationUnitId",
                        column: x => x.OrganizationUnitId,
                        principalTable: "KpOrganizationUnits",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpTables",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(nullable: true),
                    TableName = table.Column<string>(nullable: true),
                    Description = table.Column<string>(nullable: true),
                    DataBaseTypeId = table.Column<int>(nullable: false),
                    IsAutoGenerateTable = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpTables", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpTables_KpTableDataBases_DataBaseTypeId",
                        column: x => x.DataBaseTypeId,
                        principalTable: "KpTableDataBases",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpAttachment",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    FileName = table.Column<string>(maxLength: 80, nullable: false),
                    ContractionsFileName = table.Column<string>(maxLength: 80, nullable: false),
                    DisplayName = table.Column<string>(maxLength: 200, nullable: false),
                    FileFolderPath = table.Column<string>(maxLength: 200, nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    ContentType = table.Column<string>(maxLength: 128, nullable: true),
                    FileExtension = table.Column<string>(maxLength: 20, nullable: false),
                    SizeKb = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpAttachment", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpAttachment_KpUsers_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpEntityChangeSets",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    BrowserInfo = table.Column<string>(maxLength: 512, nullable: true),
                    ClientIpAddress = table.Column<string>(maxLength: 64, nullable: true),
                    ClientName = table.Column<string>(maxLength: 128, nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    ExtensionData = table.Column<string>(nullable: true),
                    ImpersonatorTenantId = table.Column<int>(nullable: true),
                    ImpersonatorUserId = table.Column<long>(nullable: true),
                    Reason = table.Column<string>(maxLength: 256, nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: true),
                    Discriminator = table.Column<string>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpEntityChangeSets", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpEntityChangeSets_KpUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpPermissions",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(maxLength: 128, nullable: false),
                    IsGranted = table.Column<bool>(nullable: false),
                    Discriminator = table.Column<string>(nullable: false),
                    RoleId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpPermissions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpPermissions_KpUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpRoles",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(maxLength: 32, nullable: false),
                    DisplayName = table.Column<string>(maxLength: 64, nullable: false),
                    IsStatic = table.Column<bool>(nullable: false),
                    IsDefault = table.Column<bool>(nullable: false),
                    NormalizedName = table.Column<string>(maxLength: 32, nullable: false),
                    ConcurrencyStamp = table.Column<string>(maxLength: 128, nullable: true),
                    Description = table.Column<string>(maxLength: 5000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpRoles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpRoles_KpUsers_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpRoles_KpUsers_DeleterUserId",
                        column: x => x.DeleterUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpRoles_KpUsers_LastModifierUserId",
                        column: x => x.LastModifierUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpSettings",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: true),
                    Name = table.Column<string>(maxLength: 256, nullable: false),
                    Value = table.Column<string>(maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpSettings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpSettings_KpUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpTenants",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenancyName = table.Column<string>(maxLength: 64, nullable: false),
                    Name = table.Column<string>(maxLength: 128, nullable: false),
                    ConnectionString = table.Column<string>(maxLength: 1024, nullable: true),
                    IsActive = table.Column<bool>(nullable: false),
                    EditionId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpTenants", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpTenants_KpUsers_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpTenants_KpUsers_DeleterUserId",
                        column: x => x.DeleterUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpTenants_KpEditions_EditionId",
                        column: x => x.EditionId,
                        principalTable: "KpEditions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpTenants_KpUsers_LastModifierUserId",
                        column: x => x.LastModifierUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpUserClaims",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    ClaimType = table.Column<string>(maxLength: 256, nullable: true),
                    ClaimValue = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpUserClaims", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpUserClaims_KpUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpUserLogins",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    LoginProvider = table.Column<string>(maxLength: 128, nullable: false),
                    ProviderKey = table.Column<string>(maxLength: 256, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpUserLogins", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpUserLogins_KpUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpUserRoles",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    RoleId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpUserRoles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpUserRoles_KpUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpUserTokens",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    LoginProvider = table.Column<string>(maxLength: 128, nullable: true),
                    Name = table.Column<string>(maxLength: 128, nullable: true),
                    Value = table.Column<string>(maxLength: 512, nullable: true),
                    ExpireDate = table.Column<DateTime>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpUserTokens", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpUserTokens_KpUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpTableColumns",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TableId = table.Column<int>(nullable: false),
                    Name = table.Column<string>(nullable: true),
                    Type = table.Column<byte>(nullable: false),
                    Length = table.Column<int>(nullable: false),
                    IsNotNull = table.Column<bool>(nullable: false),
                    IsPrimaryKey = table.Column<bool>(nullable: false),
                    ForeignKeyTableId = table.Column<int>(nullable: true),
                    ForeignKeyTableName = table.Column<string>(nullable: true),
                    ForeignKeyColumnId = table.Column<int>(nullable: true),
                    ForeignKeyColumnName = table.Column<string>(nullable: true),
                    Order = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpTableColumns", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpTableColumns_KpTableColumns_ForeignKeyColumnId",
                        column: x => x.ForeignKeyColumnId,
                        principalTable: "KpTableColumns",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpTableColumns_KpTables_ForeignKeyTableId",
                        column: x => x.ForeignKeyTableId,
                        principalTable: "KpTables",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpTableColumns_KpTables_TableId",
                        column: x => x.TableId,
                        principalTable: "KpTables",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpEntityChanges",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ChangeTime = table.Column<DateTime>(nullable: false),
                    ChangeType = table.Column<byte>(nullable: false),
                    EntityChangeSetId = table.Column<long>(nullable: false),
                    EntityId = table.Column<string>(maxLength: 48, nullable: true),
                    EntityTypeFullName = table.Column<string>(maxLength: 192, nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Discriminator = table.Column<string>(nullable: false),
                    EntityAliasName = table.Column<string>(nullable: true),
                    TableName = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpEntityChanges", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpEntityChanges_KpEntityChangeSets_EntityChangeSetId",
                        column: x => x.EntityChangeSetId,
                        principalTable: "KpEntityChangeSets",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpAuthorityRole",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    AuthorityId = table.Column<int>(nullable: false),
                    RoleId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpAuthorityRole", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpAuthorityRole_KpAuthority_AuthorityId",
                        column: x => x.AuthorityId,
                        principalTable: "KpAuthority",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_KpAuthorityRole_KpRoles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "KpRoles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpRoleClaims",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    RoleId = table.Column<int>(nullable: false),
                    ClaimType = table.Column<string>(maxLength: 256, nullable: true),
                    ClaimValue = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpRoleClaims", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpRoleClaims_KpRoles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "KpRoles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpNavigation",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ParentId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(maxLength: 100, nullable: true),
                    Code = table.Column<string>(maxLength: 100, nullable: true),
                    ActionUrl = table.Column<string>(maxLength: 100, nullable: true),
                    Icon = table.Column<string>(maxLength: 50, nullable: true),
                    IsHide = table.Column<bool>(nullable: false),
                    Level = table.Column<byte>(nullable: false),
                    Order = table.Column<byte>(nullable: false),
                    IdPath = table.Column<string>(maxLength: 100, nullable: true),
                    NamePath = table.Column<string>(maxLength: 100, nullable: true),
                    Type = table.Column<byte>(nullable: false),
                    Description = table.Column<string>(maxLength: 300, nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpNavigation", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpNavigation_KpUsers_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpNavigation_KpNavigation_ParentId",
                        column: x => x.ParentId,
                        principalTable: "KpNavigation",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpNavigation_KpTenants_TenantId",
                        column: x => x.TenantId,
                        principalTable: "KpTenants",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpEntityPropertyChanges",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    EntityChangeId = table.Column<long>(nullable: false),
                    NewValue = table.Column<string>(maxLength: 512, nullable: true),
                    OriginalValue = table.Column<string>(maxLength: 512, nullable: true),
                    PropertyName = table.Column<string>(maxLength: 96, nullable: true),
                    PropertyTypeFullName = table.Column<string>(maxLength: 192, nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Discriminator = table.Column<string>(nullable: false),
                    PropertyAliasName = table.Column<string>(nullable: true),
                    ColumnName = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpEntityPropertyChanges", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpEntityPropertyChanges_KpEntityChanges_EntityChangeId",
                        column: x => x.EntityChangeId,
                        principalTable: "KpEntityChanges",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_KpEntityPropertyChanges_KpEntityChanges_EntityChangeId1",
                        column: x => x.EntityChangeId,
                        principalTable: "KpEntityChanges",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpEditionNavigation",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    NavigationId = table.Column<int>(nullable: false),
                    EditionId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpEditionNavigation", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpEditionNavigation_KpEditions_EditionId",
                        column: x => x.EditionId,
                        principalTable: "KpEditions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_KpEditionNavigation_KpNavigation_NavigationId",
                        column: x => x.NavigationId,
                        principalTable: "KpNavigation",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpNavigationRole",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    NavigationId = table.Column<int>(nullable: false),
                    RoleId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpNavigationRole", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpNavigationRole_KpNavigation_NavigationId",
                        column: x => x.NavigationId,
                        principalTable: "KpNavigation",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_KpNavigationRole_KpRoles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "KpRoles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpQueryGrid",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(nullable: true),
                    Code = table.Column<string>(nullable: true),
                    SelectSql = table.Column<string>(nullable: true),
                    ExportSql = table.Column<string>(nullable: true),
                    Description = table.Column<string>(nullable: true),
                    IsAutoLoad = table.Column<bool>(nullable: false),
                    NavigationId = table.Column<int>(nullable: true),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpQueryGrid", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpQueryGrid_KpUsers_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "KpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpQueryGrid_KpNavigation_NavigationId",
                        column: x => x.NavigationId,
                        principalTable: "KpNavigation",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "KpQueryGridColumn",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(nullable: true),
                    Alias = table.Column<string>(nullable: true),
                    IsHidden = table.Column<bool>(nullable: false),
                    Width = table.Column<string>(nullable: true),
                    Order = table.Column<int>(nullable: false),
                    IsFilter = table.Column<bool>(nullable: false),
                    FilterConfig = table.Column<string>(nullable: true),
                    Format = table.Column<string>(nullable: true),
                    Align = table.Column<int>(nullable: false),
                    IsFrozen = table.Column<bool>(nullable: false),
                    QueryId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpQueryGridColumn", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpQueryGridColumn_KpQueryGrid_QueryId",
                        column: x => x.QueryId,
                        principalTable: "KpQueryGrid",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "KpQueryCommand",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(nullable: true),
                    Icon = table.Column<string>(nullable: true),
                    Color = table.Column<string>(nullable: true),
                    IsOnlyIcon = table.Column<string>(nullable: true),
                    ActionUrl = table.Column<string>(nullable: true),
                    Paras = table.Column<string>(nullable: true),
                    IsNeedConfirm = table.Column<string>(nullable: true),
                    CommandType = table.Column<int>(nullable: false),
                    QueryId = table.Column<int>(nullable: true),
                    ColumnId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpQueryCommand", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KpQueryCommand_KpQueryGridColumn_ColumnId",
                        column: x => x.ColumnId,
                        principalTable: "KpQueryGridColumn",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_KpQueryCommand_KpQueryGrid_QueryId",
                        column: x => x.QueryId,
                        principalTable: "KpQueryGrid",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_KpAttachment_CreatorUserId",
                table: "KpAttachment",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpAuditLogs_TenantId_ExecutionDuration",
                table: "KpAuditLogs",
                columns: new[] { "TenantId", "ExecutionDuration" });

            migrationBuilder.CreateIndex(
                name: "IX_KpAuditLogs_TenantId_ExecutionTime",
                table: "KpAuditLogs",
                columns: new[] { "TenantId", "ExecutionTime" });

            migrationBuilder.CreateIndex(
                name: "IX_KpAuditLogs_TenantId_UserId",
                table: "KpAuditLogs",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpAuthorityRole_RoleId",
                table: "KpAuthorityRole",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_KpAuthorityRole_AuthorityId_RoleId",
                table: "KpAuthorityRole",
                columns: new[] { "AuthorityId", "RoleId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpBackgroundJobs_IsAbandoned_NextTryTime",
                table: "KpBackgroundJobs",
                columns: new[] { "IsAbandoned", "NextTryTime" });

            migrationBuilder.CreateIndex(
                name: "IX_KpEditionNavigation_EditionId",
                table: "KpEditionNavigation",
                column: "EditionId");

            migrationBuilder.CreateIndex(
                name: "IX_KpEditionNavigation_NavigationId_EditionId",
                table: "KpEditionNavigation",
                columns: new[] { "NavigationId", "EditionId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpEntityChanges_EntityChangeSetId",
                table: "KpEntityChanges",
                column: "EntityChangeSetId");

            migrationBuilder.CreateIndex(
                name: "IX_KpEntityChanges_EntityTypeFullName_EntityId",
                table: "KpEntityChanges",
                columns: new[] { "EntityTypeFullName", "EntityId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpEntityChangeSets_TenantId_CreationTime",
                table: "KpEntityChangeSets",
                columns: new[] { "TenantId", "CreationTime" });

            migrationBuilder.CreateIndex(
                name: "IX_KpEntityChangeSets_TenantId_Reason",
                table: "KpEntityChangeSets",
                columns: new[] { "TenantId", "Reason" });

            migrationBuilder.CreateIndex(
                name: "IX_KpEntityChangeSets_TenantId_UserId",
                table: "KpEntityChangeSets",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpEntityChangeSets_UserId",
                table: "KpEntityChangeSets",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpEntityPropertyChanges_EntityChangeId",
                table: "KpEntityPropertyChanges",
                column: "EntityChangeId");

            migrationBuilder.CreateIndex(
                name: "IX_KpFeatures_EditionId_Name",
                table: "KpFeatures",
                columns: new[] { "EditionId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_KpFeatures_TenantId_Name",
                table: "KpFeatures",
                columns: new[] { "TenantId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_KpLanguages_TenantId_Name",
                table: "KpLanguages",
                columns: new[] { "TenantId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_KpLanguageTexts_TenantId_Source_LanguageName_Key",
                table: "KpLanguageTexts",
                columns: new[] { "TenantId", "Source", "LanguageName", "Key" });

            migrationBuilder.CreateIndex(
                name: "IX_KpNavigation_CreatorUserId",
                table: "KpNavigation",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpNavigation_ParentId",
                table: "KpNavigation",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_KpNavigation_TenantId",
                table: "KpNavigation",
                column: "TenantId");

            migrationBuilder.CreateIndex(
                name: "IX_KpNavigationRole_RoleId",
                table: "KpNavigationRole",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_KpNavigationRole_NavigationId_RoleId",
                table: "KpNavigationRole",
                columns: new[] { "NavigationId", "RoleId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpNotificationSubscriptions_NotificationName_EntityTypeName_~",
                table: "KpNotificationSubscriptions",
                columns: new[] { "NotificationName", "EntityTypeName", "EntityId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpNotificationSubscriptions_TenantId_NotificationName_Entity~",
                table: "KpNotificationSubscriptions",
                columns: new[] { "TenantId", "NotificationName", "EntityTypeName", "EntityId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpOrganizationUnits_ParentId",
                table: "KpOrganizationUnits",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_KpOrganizationUnits_TenantId_Code",
                table: "KpOrganizationUnits",
                columns: new[] { "TenantId", "Code" });

            migrationBuilder.CreateIndex(
                name: "IX_KpPermissions_TenantId_Name",
                table: "KpPermissions",
                columns: new[] { "TenantId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_KpPermissions_UserId",
                table: "KpPermissions",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpQueryCommand_ColumnId",
                table: "KpQueryCommand",
                column: "ColumnId");

            migrationBuilder.CreateIndex(
                name: "IX_KpQueryCommand_QueryId",
                table: "KpQueryCommand",
                column: "QueryId");

            migrationBuilder.CreateIndex(
                name: "IX_KpQueryGrid_CreatorUserId",
                table: "KpQueryGrid",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpQueryGrid_NavigationId",
                table: "KpQueryGrid",
                column: "NavigationId");

            migrationBuilder.CreateIndex(
                name: "IX_KpQueryGridColumn_QueryId",
                table: "KpQueryGridColumn",
                column: "QueryId");

            migrationBuilder.CreateIndex(
                name: "IX_KpRoleClaims_RoleId",
                table: "KpRoleClaims",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_KpRoleClaims_TenantId_ClaimType",
                table: "KpRoleClaims",
                columns: new[] { "TenantId", "ClaimType" });

            migrationBuilder.CreateIndex(
                name: "IX_KpRoles_CreatorUserId",
                table: "KpRoles",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpRoles_DeleterUserId",
                table: "KpRoles",
                column: "DeleterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpRoles_LastModifierUserId",
                table: "KpRoles",
                column: "LastModifierUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpRoles_TenantId_NormalizedName",
                table: "KpRoles",
                columns: new[] { "TenantId", "NormalizedName" });

            migrationBuilder.CreateIndex(
                name: "IX_KpSettings_UserId",
                table: "KpSettings",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpSettings_TenantId_Name",
                table: "KpSettings",
                columns: new[] { "TenantId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_KpTableCategory_ParentId",
                table: "KpTableCategory",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTableColumns_ForeignKeyColumnId",
                table: "KpTableColumns",
                column: "ForeignKeyColumnId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTableColumns_ForeignKeyTableId",
                table: "KpTableColumns",
                column: "ForeignKeyTableId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTableColumns_TableId",
                table: "KpTableColumns",
                column: "TableId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTables_DataBaseTypeId",
                table: "KpTables",
                column: "DataBaseTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTenantNotifications_TenantId",
                table: "KpTenantNotifications",
                column: "TenantId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTenants_CreatorUserId",
                table: "KpTenants",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTenants_DeleterUserId",
                table: "KpTenants",
                column: "DeleterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTenants_EditionId",
                table: "KpTenants",
                column: "EditionId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTenants_LastModifierUserId",
                table: "KpTenants",
                column: "LastModifierUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpTenants_TenancyName",
                table: "KpTenants",
                column: "TenancyName");

            migrationBuilder.CreateIndex(
                name: "IX_KpUserAccounts_EmailAddress",
                table: "KpUserAccounts",
                column: "EmailAddress");

            migrationBuilder.CreateIndex(
                name: "IX_KpUserAccounts_UserName",
                table: "KpUserAccounts",
                column: "UserName");

            migrationBuilder.CreateIndex(
                name: "IX_KpUserAccounts_TenantId_EmailAddress",
                table: "KpUserAccounts",
                columns: new[] { "TenantId", "EmailAddress" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserAccounts_TenantId_UserId",
                table: "KpUserAccounts",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserAccounts_TenantId_UserName",
                table: "KpUserAccounts",
                columns: new[] { "TenantId", "UserName" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserClaims_UserId",
                table: "KpUserClaims",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpUserClaims_TenantId_ClaimType",
                table: "KpUserClaims",
                columns: new[] { "TenantId", "ClaimType" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserLoginAttempts_UserId_TenantId",
                table: "KpUserLoginAttempts",
                columns: new[] { "UserId", "TenantId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserLoginAttempts_TenancyName_UserNameOrEmailAddress_Result",
                table: "KpUserLoginAttempts",
                columns: new[] { "TenancyName", "UserNameOrEmailAddress", "Result" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserLogins_UserId",
                table: "KpUserLogins",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpUserLogins_TenantId_UserId",
                table: "KpUserLogins",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserLogins_TenantId_LoginProvider_ProviderKey",
                table: "KpUserLogins",
                columns: new[] { "TenantId", "LoginProvider", "ProviderKey" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserNotifications_UserId_State_CreationTime",
                table: "KpUserNotifications",
                columns: new[] { "UserId", "State", "CreationTime" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserOrganizationUnits_TenantId_OrganizationUnitId",
                table: "KpUserOrganizationUnits",
                columns: new[] { "TenantId", "OrganizationUnitId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserOrganizationUnits_TenantId_UserId",
                table: "KpUserOrganizationUnits",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserRoles_UserId",
                table: "KpUserRoles",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpUserRoles_TenantId_RoleId",
                table: "KpUserRoles",
                columns: new[] { "TenantId", "RoleId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserRoles_TenantId_UserId",
                table: "KpUserRoles",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUsers_CreatorUserId",
                table: "KpUsers",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpUsers_DeleterUserId",
                table: "KpUsers",
                column: "DeleterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpUsers_LastModifierUserId",
                table: "KpUsers",
                column: "LastModifierUserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpUsers_OrganizationUnitId",
                table: "KpUsers",
                column: "OrganizationUnitId");

            migrationBuilder.CreateIndex(
                name: "IX_KpUsers_TenantId_NormalizedEmailAddress",
                table: "KpUsers",
                columns: new[] { "TenantId", "NormalizedEmailAddress" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUsers_TenantId_NormalizedUserName",
                table: "KpUsers",
                columns: new[] { "TenantId", "NormalizedUserName" });

            migrationBuilder.CreateIndex(
                name: "IX_KpUserTokens_UserId",
                table: "KpUserTokens",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_KpUserTokens_TenantId_UserId",
                table: "KpUserTokens",
                columns: new[] { "TenantId", "UserId" });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "KpAttachment");

            migrationBuilder.DropTable(
                name: "KpAuditLogs");

            migrationBuilder.DropTable(
                name: "KpAuthorityRole");

            migrationBuilder.DropTable(
                name: "KpBackgroundJobs");

            migrationBuilder.DropTable(
                name: "KpEditionNavigation");

            migrationBuilder.DropTable(
                name: "KpEntityPropertyChanges");

            migrationBuilder.DropTable(
                name: "KpFeatures");

            migrationBuilder.DropTable(
                name: "KpLanguages");

            migrationBuilder.DropTable(
                name: "KpLanguageTexts");

            migrationBuilder.DropTable(
                name: "KpNavigationRole");

            migrationBuilder.DropTable(
                name: "KpNotifications");

            migrationBuilder.DropTable(
                name: "KpNotificationSubscriptions");

            migrationBuilder.DropTable(
                name: "KpPermissions");

            migrationBuilder.DropTable(
                name: "KpQueryCommand");

            migrationBuilder.DropTable(
                name: "KpRoleClaims");

            migrationBuilder.DropTable(
                name: "KpSettings");

            migrationBuilder.DropTable(
                name: "KpSystemIcon");

            migrationBuilder.DropTable(
                name: "KpTableCategory");

            migrationBuilder.DropTable(
                name: "KpTableColumns");

            migrationBuilder.DropTable(
                name: "KpTenantNotifications");

            migrationBuilder.DropTable(
                name: "KpUserAccounts");

            migrationBuilder.DropTable(
                name: "KpUserClaims");

            migrationBuilder.DropTable(
                name: "KpUserLoginAttempts");

            migrationBuilder.DropTable(
                name: "KpUserLogins");

            migrationBuilder.DropTable(
                name: "KpUserNotifications");

            migrationBuilder.DropTable(
                name: "KpUserOrganizationUnits");

            migrationBuilder.DropTable(
                name: "KpUserRoles");

            migrationBuilder.DropTable(
                name: "KpUserTokens");

            migrationBuilder.DropTable(
                name: "KpAuthority");

            migrationBuilder.DropTable(
                name: "KpEntityChanges");

            migrationBuilder.DropTable(
                name: "KpQueryGridColumn");

            migrationBuilder.DropTable(
                name: "KpRoles");

            migrationBuilder.DropTable(
                name: "KpTables");

            migrationBuilder.DropTable(
                name: "KpEntityChangeSets");

            migrationBuilder.DropTable(
                name: "KpQueryGrid");

            migrationBuilder.DropTable(
                name: "KpTableDataBases");

            migrationBuilder.DropTable(
                name: "KpNavigation");

            migrationBuilder.DropTable(
                name: "KpTenants");

            migrationBuilder.DropTable(
                name: "KpUsers");

            migrationBuilder.DropTable(
                name: "KpEditions");

            migrationBuilder.DropTable(
                name: "KpOrganizationUnits");
        }
    }
}
